package com.klarna.raas.ws.dao;

import java.math.BigDecimal;
import java.math.BigInteger;
import java.util.List;

import javax.sql.DataSource;

import org.apache.log4j.Logger;
import org.springframework.jdbc.core.JdbcTemplate;

import com.klarna.raas.ws.dao.mapper.PersonRowMapper;
import com.klarna.raas.ws.domain.PersonInfo;
import com.klarna.raas.ws.services.LookupService;

public class PersonDaoImpl implements IPersonDao {

	private static final Logger logger = Logger.getLogger(LookupService.class);
	private DataSource dataSource;


	public void setDataSource(DataSource ds) {
		dataSource = ds;
	}

/*	public List<PersonInfo> select(String id) {
		logger.info("PersonDaoImpl:select START");
		BigDecimal bigIntId = new BigDecimal(new BigInteger(id), 0);
		JdbcTemplate select = new JdbcTemplate(dataSource);
		return select
				.query("SELECT * FROM petter_engstrom.SUPPLIER_INPUT_DATA WHERE ID = ?",
						new Object[] { bigIntId },
						new PersonRowMapper());
		
	}
*/
	
	public List<PersonInfo> select(String id) {
		logger.info("PersonDaoImpl:select START");
		BigDecimal bigIntId = new BigDecimal(new BigInteger(id), 0);
		JdbcTemplate select = new JdbcTemplate(dataSource);
		List<PersonInfo> pList = select
				.query("SELECT * FROM petter_engstrom.SUPPLIER_INPUT_DATA WHERE ID = ?",
						new Object[] { bigIntId },
						new PersonRowMapper());
		logger.info("PersonDaoImpl:select END");

		return pList;
	}

		public List<PersonInfo> selectMultipleParams(String birthDate, String firstName,
			String lastName, String street, String zip) {
		logger.info("PersonDaoImpl:selectMultipleParams START");
		String paramsMessage = "Params recieved[" +
				"birthDate=" + birthDate
				+ ",firstName=" + firstName
				+ ",lastName=" + lastName
				+ ",street=" + street
				+ ",zip=" + zip
				+ "]";
		
		logger.info(paramsMessage);

		JdbcTemplate select = new JdbcTemplate(dataSource);
		List<PersonInfo> pList = select
				.query("SELECT * FROM petter_engstrom.SUPPLIER_INPUT_DATA WHERE BIRTH_DATE = ? AND FIRST_NAME = ? AND LAST_NAME = ? AND STREET = ? AND ZIP = ?",
						new Object[] { birthDate, firstName, lastName, street, zip},
						new PersonRowMapper());
		logger.info("PersonDaoImpl:selectMultipleParams END");

		return pList;
	}

}


